

# locustfile.py
from locust import HttpUser, task, between


# 父类是个User,表示要生成进行负载测试的系统的 HTTP“用户”。每个user相当于一个协程链接 ，进行相关系统交互操作
class ChatUser(HttpUser):
    # 装饰器来标记为一个测试任务, 表示用户要进行的操作:访问首页 → 登录 → 增、删改查
    @task
    def chat_completions(self):
        # wait_time = between(3, 5)
        # self.client发送 HTTP 请求，模拟用户的操作
        self.client.post("/v1/chat/completions", json={
                "model": "/home/llm/qwq32",
                "temperature": 0.5,
                "max_tokens": 100,
                "messages": [
                    {
                        "role": "user",
                        "content": "你是谁,你在哪,讲一个笑话"
                    }
                ]
        })


# class MyApiUser(HttpUser):
#     wait_time = between(1, 5)  # 每个请求之间的等待时间
#
#     @task(1)  # 高优先级任务的权重为3
#     def high_priority_request(self):
#         headers = {"X-Priority": "high", "Content-Type": "application/json"}
#         data = {
#             "model": "/dev/shm/llm/deepseek-1.5/",
#             "temperature": 0.5,
#             "max_tokens": 9000,
#             "messages": [
#                 {
#                     "role": "user",
#                     "content": "你在哪"
#                 }
#             ],
#             "priority": 1
#         }
#         self.client.post("/v1/chat/completions", json=data, headers=headers)
#
#     @task(1)  # 低优先级任务的权重为1
#     def low_priority_request(self):
#         headers = {"X-Priority": "low", "Content-Type": "application/json"}
#         data = {
#             "model": "/dev/shm/llm/deepseek-1.5/",
#             "temperature": 0.5,
#             "max_tokens": 9000,
#             "messages": [
#                 {
#                     "role": "user",
#                     "content": "你在哪"
#                 }
#             ],
#             "priority": 2
#         }
#         self.client.post("/v1/chat/completions", json=data, headers=headers)
